//
//  TabBarController.m
//  DianDangDai
//
//  Created by bhf on 2017/12/12.
//  Copyright © 2017年 bhf. All rights reserved.
//

#import "TabBarController.h"
#import "SegmentController.h"
@interface TabBarController ()

@end

@implementation TabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setUpTabBarController];
    [self requestData];
    // Do any additional setup after loading the view.
}
//设置tabbar

- (void)setUpTabBarController {
    
    self.tabBar.translucent = NO;
    
    UIStoryboard *board1 = [UIStoryboard storyboardWithName:@"HomePage" bundle:[NSBundle mainBundle]];
    UIViewController *hp = [board1 instantiateViewControllerWithIdentifier:@"hp"];
    hp.tabBarItem.image = [UIImage imageNamed:@"home1-1"];
    hp.tabBarItem.title = @"首页";
    UIStoryboard *board3 = [UIStoryboard storyboardWithName:@"BrrowMoney" bundle:[NSBundle mainBundle]];
    UIViewController *bm = [board3 instantiateViewControllerWithIdentifier:@"imt"];
    bm.tabBarItem.image = [UIImage imageNamed:@"loan-1"];
    bm.tabBarItem.title = @"借款";
    UIStoryboard *board2 = [UIStoryboard storyboardWithName:@"Investment" bundle:[NSBundle mainBundle]];
    UIViewController *sc = [board2 instantiateViewControllerWithIdentifier:@"sgc"];
    sc.tabBarItem.image = [UIImage imageNamed:@"investment1-1"];
    sc.tabBarItem.title = @"出借";
//    SegmentController *sc = [[SegmentController alloc] init];
//    sc.tabBarItem.image = [UIImage imageNamed:@"investment1-1"];
//    sc.tabBarItem.title = @"出借";
    
    UIStoryboard *board4 = [UIStoryboard storyboardWithName:@"My" bundle:[NSBundle mainBundle]];
    UIViewController *my = [board4 instantiateViewControllerWithIdentifier:@"my"];
    my.tabBarItem.image = [UIImage imageNamed:@"my-1"];
    my.tabBarItem.title = @"我的";
    
    self.viewControllers = @[hp,sc,bm,my];
    
}
- (void)requestData {
    NSDictionary *userInformation = [[NSUserDefaults standardUserDefaults] dictionaryForKey:@"userInformation"];
    NSString *sign = userInformation[@"sign"];
    NSString *urlString = [NSString stringWithFormat:@"%@OPT=1018&sign=%@",API_LOGIN_URL_STRING,sign];
    [[CDHttpHelper defaultCDHttpHelper] get:urlString params:nil success:^(id responseObj) {
        NSDictionary *dict = [responseObj objectFromJSONData];
        NSLog(@"%@",dict);
        NSInteger code = [dict[@"code"] integerValue];
        if (code == -1) {
            [self.view makeToast:dict[@"msg"]];
            NSUserDefaults *df = [NSUserDefaults standardUserDefaults];
            [df synchronize];
            [df setObject:@"No" forKey:@"login"];
        } else if (code == 0) {
            NSUserDefaults *df = [NSUserDefaults standardUserDefaults];
            [df synchronize];
            [df setObject:@"Yes" forKey:@"login"];
        }
    } failure:^(NSError *error) {
        
    } showHUD:NO];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
